// RHGenericSPI.h
// Author: Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2011 Mike McCauley
// Contributed by Joanna Rutkowska
// $Id: RHGenericSPI.h,v 1.9 2020/01/05 07:02:23 mikem Exp $

#ifndef RHGenericSPI_h
#define RHGenericSPI_h

#include "RadioHead.h"

class RHGenericSPI
{
public:
  typedef enum
    { DataMode0 = 0,
      DataMode1,
      DataMode2,
      DataMode3,
    } DataMode;

  typedef enum
    { Frequency1MHz = 0,
      Frequency2MHz,
      Frequency4MHz,
      Frequency8MHz,
      Frequency16MHz
    } Frequency;

  typedef enum
    { BitOrderMSBFirst = 0,
      BitOrderLSBFirst,
    } BitOrder;

  RHGenericSPI (Frequency frequency = Frequency1MHz, BitOrder bitOrder = BitOrderMSBFirst,
		DataMode dataMode = DataMode0);

  virtual uint8_t transfer(uint8_t data) = 0;

#if (RH_PLATFORM == RH_PLATFORM_MONGOOSE_OS)
  virtual uint8_t transfer2B(uint8_t byte0, uint8_t byte1) = 0;
  virtual uint8_t spiBurstRead(uint8_t reg, uint8_t* dest, uint8_t len) = 0;
  virtual uint8_t spiBurstWrite(uint8_t reg, const uint8_t* src, uint8_t len) = 0;
#endif

  virtual void attachInterrupt() {};
  virtual void detachInterrupt() {};
  virtual void begin() = 0;
  virtual void end() = 0;
  virtual void setBitOrder(BitOrder bitOrder);
  virtual void setDataMode(DataMode dataMode);
  virtual void setFrequency(Frequency frequency);
  virtual void beginTransaction(){}
  virtual void endTransaction(){}
  virtual void usingInterrupt(uint8_t interruptNumber) { (void)interruptNumber; }

protected:
  Frequency    _frequency; // Bus frequency, one of RHGenericSPI::Frequency
  BitOrder     _bitOrder;
  DataMode     _dataMode;
};

#endif
